package com.yami.shop.multishop.controller;

import com.yami.shop.bean.model.ShopPayWxSetting;
import com.yami.shop.service.ShopPayWxSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 店铺微信支付设置Controller
 */
@RestController
@RequestMapping("/shop/pay/wxsetting")
@Api(tags = "店铺微信支付设置接口")
@Slf4j
public class ShopPayWxSettingController {

    @Autowired
    private ShopPayWxSettingService shopPayWxSettingService;

    @GetMapping("/info")
    @ApiOperation(value = "获取店铺微信支付设置")
    public ResponseEntity<ShopPayWxSetting> getShopPayWxSetting(@ApiParam("店铺ID") @RequestParam Long shopId) {
        try {
            ShopPayWxSetting shopPayWxSetting = shopPayWxSettingService.getShopPayWxSetting(shopId);
            return ResponseEntity.ok(shopPayWxSetting);
        } catch (Exception e) {
            log.error("获取店铺微信支付设置失败", e);
            return ResponseEntity.badRequest().build();
        }
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新店铺微信支付设置")
    public ResponseEntity<Void> updateShopPayWxSetting(@Valid @RequestBody ShopPayWxSetting shopPayWxSetting) {
        try {
            shopPayWxSettingService.updateShopPayWxSetting(shopPayWxSetting);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            log.error("更新店铺微信支付设置失败", e);
            return ResponseEntity.badRequest().build();
        }
    }

    @PostMapping("/update-withdrawal-method")
    @ApiOperation(value = "更新提现方式")
    public ResponseEntity<Void> updateWithdrawalMethod(
            @ApiParam("店铺ID") @RequestParam Long shopId,
            @ApiParam("提现方式（0-手动 1-自动）") @RequestParam Integer withdrawalMethod) {
        try {
            shopPayWxSettingService.updateWithdrawalMethod(shopId, withdrawalMethod);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            log.error("更新提现方式失败", e);
            return ResponseEntity.badRequest().build();
        }
    }
} 